package com.alibaba.shopping_search_customer_api.controller;

import com.alibaba.shopping_common.pojo.GoodsDesc;
import com.alibaba.shopping_common.pojo.GoodsSearchParam;
import com.alibaba.shopping_common.pojo.GoodsSearchResult;
import com.alibaba.shopping_common.result.BaseResult;
import com.alibaba.shopping_common.service.GoodsService;
import com.alibaba.shopping_common.service.SearchService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GoodsSearchController
 * @Description TODO
 * @Author Leo
 * @Date 2024/12/13 11:28
 */
@RestController
@RequestMapping("/user/goodsSearch")
public class GoodsSearchController {

    @DubboReference
    private SearchService searchService;

    @DubboReference
    private GoodsService goodsService;

    /**
     * 自动补齐关键词
     * @param keyword 用户输入的搜索关键词
     * @return
     */
    @GetMapping("/autoSuggest")
    private BaseResult<List<String>>autoSuggest(String keyword){
        List<String> list = searchService.autoSuggest(keyword);
        return BaseResult.OK(list);
    }

    /**
     * 搜索商品
     * @param goodsSearchParam 搜索条件
     * @return 搜索结果
     */
    @PostMapping("/search")
    public BaseResult<GoodsSearchResult> search(@RequestBody GoodsSearchParam goodsSearchParam){
        GoodsSearchResult result = searchService.search(goodsSearchParam);
        return BaseResult.OK(result);
    }

    /**
     * 根据ID查询商品详情
     * @param id 商品ID
     * @return
     */
    @GetMapping("/findDesc")
    public BaseResult<GoodsDesc> findDesc(Long id){
        GoodsDesc goodsDesc = goodsService.findDescById(id);
        return BaseResult.OK(goodsDesc);
    }

}




